package com.lgkj.ui;

import android.util.Log;
import android.view.MotionEvent;
import android.widget.ImageView;

import com.lgkj.R;
import com.lgkj.utils.CommonUtils;

import java.io.File;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/7/7 0007.
 */

public class ImageBrowseActivity extends BaseActivity {
    @BindView(R.id.picture_display_image)
    ImageView pictureDisplayImage;
    int downX = 0;
    int moveX = 0;
    int upX = 0;

    @Override
    public int getLayoutId() {
        return R.layout.activity_image_browse;
    }

    @Override
    public void initView() {
        String url = getIntent().getStringExtra("image_url");
        boolean loadpath = getIntent().getBooleanExtra("loadpath", false);
        if (url != null && !loadpath) {
            CommonUtils.LoadImage(ImageBrowseActivity.this, pictureDisplayImage, url, 0);
        } else {
            CommonUtils.LoadImage(ImageBrowseActivity.this, pictureDisplayImage, new File(url), 0);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN://获取点击的时候屏幕位置
                downX = (int) event.getRawX();
                // LogUtil.e("NSC","x = "+x+"  y="+y);
                break;
            case MotionEvent.ACTION_MOVE:
                moveX = (int) event.getRawX();
                //LogUtil.e("NSC","mx = "+mx+"  my="+my);
                break;
            case MotionEvent.ACTION_UP://手离开的时候位置
                upX = (int) event.getRawX();
                int pValue = upX - downX;//滑动的距离差
                Log.e("NSC", "upX-downX = " + (upX - downX));

                if (pValue < -120) {//点击触摸就关闭窗口
                    finishAfterTransition();
                }

                break;
        }

        return super.onTouchEvent(event);         // 注册手势事件
    }

    @Override
    public void initData() {

    }


    @OnClick(R.id.tl_view)
    public void onClick() {
        finishAfterTransition();
    }
}
